<template>
  <div class="member-order">
    <XtxTabs v-model="activeName" @tab-click="handleClick">
      <!-- 这是注释 -->
      <XtxTabsPanel
        v-for="item in orderStatus"
        :key="item.name"
        :label="item.label"
        :name="item.name"
      ></XtxTabsPanel>
    </XtxTabs>

    <!-- 由于七个面板的内容基本一致，没有必要准备七个不同的面板，复用同一个，进行切换 -->
    <div class="order-list">
      <OrderItem v-for="item in orderList" :key="item.id" :order="item" />
    </div>
  </div>
</template>
<script>
import { orderStatus } from '@/constants/order'
import { ref, reactive, watch } from 'vue'
import OrderItem from './components/order-item'
import { reqFindOrderList } from '@/api/order'
export default {
  name: 'MemberOrder',
  components: {
    OrderItem
  },
  setup () {
    const activeName = ref('all')

    // 查询订单参数
    const requestParams = reactive({
      orderState: 0, // 全部的。 订单状态 => 和面板的下标是对应的
      page: 1,
      pageSize: 5
    })

    // 订单列表
    const orderList = ref([])
    // 查询订单
    async function getOrderList () {
      const res = await reqFindOrderList(requestParams)
      orderList.value = res.result.items
    }
    getOrderList()

    const handleClick = ({ index }) => {
      requestParams.orderState = index
    }

    watch(requestParams, () => {
      getOrderList()
    })

    return {
      orderStatus,
      activeName,
      orderList,
      handleClick
    }
  }
}
</script>

<style scoped lang="less">
.order-list {
  background: #fff;
  padding: 20px;
}
</style>
